package com.tandashi.springbootstudy01.study.thread;

public class CrossPrint {
    volatile private boolean printFlag = false;
    synchronized public void printA(){
        try {
            while (printFlag == true){
                wait();
            }
            for (int i = 0; i < 1; i++) {
                System.out.println("AAAAA");
            }
            printFlag  = true;
            notifyAll();

        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    synchronized public void printB(){
        try {
            while (printFlag == false){
                wait();
            }
            for (int i = 0; i < 1; i++) {
                System.out.println("BBBBB");
            }
            printFlag  = false;
            notifyAll();

        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

}
